package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(urlPatterns = {"*.jsp", "*.html"})
public class LoginFilter implements Filter {
    public void destroy() {
    }


    public void init(FilterConfig config) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        filterChain.doFilter(request, response);
        //如果用户访问的是登录页面login.jsp也需要直接放行
//        String requestURI = request.getRequestURI();
//        if (requestURI.contains("login.jsp")) {
//            filterChain.doFilter(request, response);
//        }else{
//            HttpSession session = request.getSession();
//            Object fullName = session.getAttribute("fullName");
//            if (fullName == null) {
//                //未经过登录授权则返回login.jsp页面
//                 response.sendRedirect("login.jsp");
//            } else {
//                filterChain.doFilter(request, response);
//            }
//
//        }

    }

}
